{php include wl_template('common/header');}

<ul class="nav nav-tabs">
<li {if $op == 'base'}class="active"{/if}><a href="{php echo web_url('member/partjob', array('op' => 'base'))}">基本设置</a></li>
{if $checkfunction['status']}	
	<li {if $op == 'display'&&$groupstatus == ''}class="active"{/if}>
        <a href="{php echo web_url('member/partjob', array('op' => 'display', 'groupstatus' =>''))}">全部记录</a>
    </li>
    <li{if $op == 'display'&&$groupstatus == 2} class="active"{/if}>
        <a href="{php echo web_url('member/partjob', array('op' => 'display', 'groupstatus' =>'2'))}">待审核</a>
    </li>
	<li {if $op == 'display'&&$groupstatus == 1} class="active"{/if}>
        <a href="{php echo web_url('member/partjob', array('op' => 'display', 'groupstatus' =>'1'))}">已审核</a>
    </li>
	
   
    <!--<li>
        <a href="{php echo $this->createWebUrl('grouporder', array('reload' =>'reload','groupstatus'=>$groupstatus))}"><button class="btn btn-success">刷新</button></a>
    </li>-->
	{if $op == 'group_detail'}
    <li class="active">
        <a href="#">订单明细</a>
    </li>
    {/if}
    {if $op == 'member_detail'}
    <li class="active">
        <a href="#">团队成员</a>
    </li>
    {/if}
	 {if $op == 'upd'}
    <li class="active">
        <a href="#">店铺设置</a>
    </li>
    {/if}
	{/if}
</ul>
{if $op == 'base'}
	
	<div class="panel panel-default">
	<div class="panel-body table-responsive" style="padding: 0px;">
		<div class="main_bd">
        <div class="plugins_wrp">
            <dl>
                <dd>
                    <ul id="js_plugins">
						<li class="item_wrp" style="width: 100%;">
							<div class="plugin_item">
								<div  id="link-icon1" class="plugin_icon" >
									<div id="link-icon" style="display:none;width:100%;height:100%;position:absolute;background-color:rgba(0,0,0,0.3);cursor:pointer;">
										<img src="{TG_URL_WRES}images/3.svg"style="position:absolute;width:60%;left:20%;">
									</div>
									<img src="https://res.wx.qq.com/mpres/zh_CN/htmledition/comm_htmledition/images/icon/service/scan.png" style="cursor:pointer;">
								</div>
								<div class="plugin_status">
									<i class="access"></i>
									<span class="status_txt">
										{if $checkfunction['status']}	
											
										<div id="renewal" style="font-size:20px;margin-top:-30px;width: 60px;height:60px;border-radius:50%;font-weight:900;background-color:#ff5466;color:white;margin-right: -25px;text-align:center;line-height:60px;cursor:pointer;">续费</div>										
								
										<span style="display:block;margin-left:-70px;color:#888;font-size:14px;">截止日期：{php echo date('Y-m-d', $checkfunction['endtime'])}</span>
										
										{else}
										
										<div id="buyDaifu" style="font-size:20px;margin-top:-20px;width: 60px;height:60px;border-radius:50%;font-weight:900;background-color:#ff5466;color:white;margin-right: -25px;text-align:center;line-height:60px;cursor:pointer;">购买</div>
										{/if}
									</span>
								</div>
								<div class="plugin_content">
									<h3 class="title">{$_W['page']['title']}</h3>
									<p class="desc" style="    width: 100%;">
										启用全民兼职后，可以去招募兼职人员，去帮助商城进行推广，配合商品设置自定义佣金，具体流程点击功能图片预览。
									</p>
								</div>
							</div>
						</li>
					</ul>
                </dd>
            </dl>
        </div>
    </div>
	</div>
</div>
	{/if}
	{if $op=='display'}
<div class="main">
{if $op!='group_detail'&&$op!='member_detail'&&$op!='upd'}
    <div class="panel panel-info">
	    <div class="panel-heading">筛选</div>
	    <div class="panel-body">
            <form action="{php echo web_url('member/partjob', array('op' => 'display'))}" method="get" class="form-horizontal" role="form" id="form1">               
                <input type="hidden" name="groupstatus" value="{$groupstatus}" />
				 <input type="hidden" name="selltype" value="{$selltype}" />
                <div class="form-group">
                    <label class="col-xs-12 col-sm-2 col-md-2 col-lg-2 control-label">昵称</label>
                    <div class="col-sm-8 col-lg-9 col-xs-12">
                        <input class="form-control" name="keyword" id="" type="text" value="{$_GPC['keyword']}" placeholder="可查询昵称">
                    </div>
                </div>
                <div class="form-group">
                        <label class="col-xs-12 col-sm-2 col-md-2 col-lg-2 control-label">申请时间</label>
                        <div class="col-sm-5 col-lg-7 col-xs-12">
                            {php echo tpl_form_field_daterange('time', array('starttime'=>date('Y-m-d', $starttime),'endtime'=>date('Y-m-d', $endtime)));}
                        </div>
                        <div class="col-sm-3 col-lg-2" style="text-align:right;"><button class="btn btn-default"><i class="fa fa-search"></i> 搜索</button>
                        </div>
                    </div>
                <div class="form-group">
                </div>
            </form>
			
          <!--  <a href='{php echo $this->createWebUrl('grouporder', array('op' => 'output','groupstatus'=>$groupstatus,'starttime'=>$starttime,'endtime'=>$endtime))}'><button class="btn btn-info"><i class="fa fa-download"></i> 导出记录</button></a>-->
	    </div>
	</div>
{/if}
	<div class="panel panel-default">
		<div class="panel-body table-responsive">
			<table class="table table-hover">
				<thead class="navbar-inner">
					<tr>
					<th style="width:10%;"></th>
						<th style="width:10%;">姓名</th>
						<th style="width:10%;">状态</th>	
						<th style="width:10%;">手机号</th>							
						<th style="width:20%;">申请时间</th>
						<th style="width:10%;">上级</th>
						<th style="width:10%;">佣金</th>
						<th style="width:20%; text-align:right;">操作</th>
					</tr>
				</thead>
				<tbody>
					{loop $members $key $item}
					 <?php
						$fee=0;
						if(empty($item['total'])){
						$sql="SELECT * FROM ".tablename('tg_order')." WHERE openid=:from_user and status not in (0,4,5,9)";
						$params = array(':from_user'=>$item['from_user']);
							$order = pdo_fetchall($sql, $params);
							$arr  = array();							
							foreach ($order as $key => $value) {
								$fee+=$value['card_fee'];
							}
							pdo_update('tg_member', array('total' => $fee), array('id' => $item['id']));
						}else{$fee=$item['total'];}
						
						$sql1 = "SELECT * FROM ".tablename('tg_address')." WHERE id=:addressid";
						$params1  = array(':addressid' => $arr['addressid']);
							$address = pdo_fetch($sql1,$params1);
						$sql="SELECT * FROM ".tablename('tg_member')." WHERE id=:id";
						$params = array(':id'=>$item['parentid']);
							$parentmember = pdo_fetch($sql, $params);
						$url=$_W['siteroot']."app/index.php?i=".$_W['uniacid']."&c=entry&do=index&m=lexiangpingou&sharenum=".$item['id'];
						?>
					<tr>
						<td><img src='{$item['avatar']}' style='width:30px;height:30px;padding1px;border:1px solid #ccc' /></td>
						<td>{$item['nickname']}</td>
						<td>
							{if $item['type']==1&& $item['enable']==0}
								<span class="label label-warning">申请中</span>
							{/if}
							{if $item['enable']==1 }
								 <span class="label label-success">已审核</span>
							{/if}
							
						</td>
						<td>
							 <span class="label label-success">{$item['mobile']}</span>
						</td>
						<td>{php echo date('Y-m-d ', $item['addtime'])}<br>{php echo date('H:i:s', $item['addtime'])}</td>
						<td>{$parentmember['nickname']}</td>
						<td>{$item['wallet']}</td>
						<td style="text-align:right;">
						<a class="btn btn-default" href="{php echo web_url('member/partjob', array('op' => 'upd','id'=>$item['id']))}" style="margin-bottom:5px">店铺设置</a>
					{if  $item['enable']==0}	<a class="btn btn-default" href="{php echo web_url('member/partjob', array('op' => 'checked','id'=>$item['id']))}" style="margin-bottom:5px"> 审核通过</a>{/if}
					{if  $item['enable']==1}
					<a class="btn btn-default" href="{php echo web_url('member/partjob', array('op' => 'member_detail','id'=>$item['id']))}" style="margin-bottom:5px">我的下级</a><br>
					<a class="btn btn-default" href="{php echo web_url('member/partjob', array('op' => 'group_detail','id'=>$item['id']))}" style="margin-bottom:5px"> 佣金明细</a>
					<a class="btn btn-default cancelJ" href="{php echo web_url('member/partjob', array('op' => 'unchecked','id'=>$item['id']))}"  style="margin-bottom:5px"> 取消兼职</a>
					{/if}
					
					<!--  <a class="btn btn-default" href="{php echo $this->createWebUrl('member', array('op'=>'modify','id'=>$item['id']))}"><i class="fa fa-edit"></i> 编辑</a>-->
                    <!--  <a class="btn btn-default" href="{php echo $this->createWebUrl('member', array('op'=>'payment','id'=>$item['id']))}"><i class="fa fa-edit"></i> 佣金发放</a>-->
					<!--	    <a href="javascript:;" class="btn btn-default" onclick="displayQr('{php echo $this->createWebUrl('qr', array('raw' => base64_encode($url)))}');"><i class="fa fa-qrcode fa-fw"></i> 查看二维码</a>-->
                           <!-- <div class="btn-group btn-group-sm">
                                <a class="btn btn-primary dropdown-toggle" data-toggle="dropdown" aria-expanded="false" href="javascript:;">宣传地址 <span class="caret"></span></a>
                                <ul class="dropdown-menu dropdown-menu-right" role="menu">
                                    <li>
                                        <a href="{$url}" target="_blank"><i class="fa fa-external-link fa-fw"></i> 直接访问</a>
                                    </li>
                                    <li role="presentation">
                                        <a href="javascript:;" onclick="displayUrl('{$url}'}');"><i class="fa fa-link fa-fw"></i> 查看链接</a>
                                    </li>
                                    <li role="presentation">
                                        <a href="javascript:;" onclick="displayQr('{php echo $this->createWebUrl('qr', array('raw' => base64_encode($url)))}');"><i class="fa fa-qrcode fa-fw"></i> 查看二维码</a>
                                    </li>
                                </ul>
                            </div>-->
						</td>
					</tr>
					{/loop}
				</tbody>
			</table>
		</div>
	</div>
</div>
{$pager}
<script type="text/javascript">
	require(['daterangepicker'], function($){
		$('.daterange').on('apply.daterangepicker', function(ev, picker) {
			$('#form1')[0].submit();
		});
	});
</script>
{/if}


{if $op=='group_detail'}
<style type="text/css">
.main .form-horizontal .form-group{margin-bottom:0;}
.main .form-horizontal .modal .form-group{margin-bottom:15px;}
#modal-confirmsend .control-label{margin-top:0;}
</style>
<div class="main">
	<form class="form-horizontal form" action="" method="post" enctype="multipart/form-data" onsubmit="return formcheck(this)">
		<input type="hidden" name="dispatchid" value="{$dispatch['id']}" />
		
	   	<div class="panel panel-default">
	   	<div class="panel-heading">
			订单明细
		</div>
	   	<div class="panel-body table-responsive">
	   		<table class="table table-hover">
	   			<thead class="navbar-inner">
	   				<tr>
	   					<th style="width:150px;">订单号</th>
	   					<th style="width:70px;">昵称</th>
	   					<th style="width:100px;">订单金额</th>
						<th style="width:100px;">提成方式</th>
						<th style="width:100px;">数值</th>
	   					<th style="width:80px;">佣金</th>	
<th style="width:80px;">是否结算</th>							
	   				</tr>
	   			</thead>
	   			<tbody>
	   				{loop $orderlist $item}
					 <?php 
					 $comprice=0;
					 $price=$item['price']-$item['cost_fee'];
if($item['g_id']>0)
{
	

if($item['commissiontype']==2)
{$comprice=$item['commission'];}
else{$comprice=$price*$item['commission']/100;}

}else{
$sql3 = 'SELECT sid,oprice,num,commission FROM '.tablename('tg_collect').' WHERE uniacid=:uniacid and orderno=:orderno';
$params3 = array(':uniacid'=>$_W['uniacid'],'orderno'=>$item['orderno']);
 $favoriteqqq = pdo_fetchall($sql3, $params3);
	
				foreach ($favoriteqqq as $key => $orderss1) 
					{				
						
						$sql4 = 'SELECT commissiontype FROM '.tablename('tg_goods').' WHERE id=:id';

                    $params4 = array(':id'=>$orderss1['sid']);

                    $gs = pdo_fetch($sql4, $params4);
						if($gs['commissiontype']==2){$comprice+=$orderss1['commission'];}
					     else{
						
							 $comprice=$comprice+$orderss1['oprice']*$orderss1['num']*$orderss1['commission']/100;//佣金计算			
						 }			
					}			
}
if($item['comtype']==1){
$billnum+=$comprice;   
}
 if($item['comtype']==0){
$nobillnum+=$comprice;   
}                
          ?>
		 
	   				<tr>
	   					<td>{$item['orderno']}</td>
	   					<td>{$item['addname']}</td>
	   					<td>{$price}</td>
						<td>{if $item['commissiontype']==2}固定金额{/if}{if $item['commissiontype']==1}百分比{/if}</td>
						<td>{$item['commission']}</td>
	   					<td>
	   					{$comprice}
	   					</td>
	   					<td>{if $item['comtype']==1}已结算{/if}{if $item['comtype']==0}未结算{/if}</td>
	   				</tr>
					
	   				{/loop}
					<tr>
	   					<td></td>
	   					<td></td>
	   					<td></td>
						<td></td>
						<td></td>
	   					<td>已结算:{$billnum}</td>
	   					<td>未结算:{$nobillnum}</td>
	   				</tr>
	   			</tbody>
	   		</table>
	   	</div>
	   	</div>
		{$total}
	</form>
</div>
{/if}
{if $op=='upd'}
<style type="text/css">
.main .form-horizontal .form-group{margin-bottom:0;}
.main .form-horizontal .modal .form-group{margin-bottom:15px;}
#modal-confirmsend .control-label{margin-top:0;}
</style>
<div class="main">
	<form action="./index.php" method="get" class="form-horizontal" role="form" id="form1">
                <input type="hidden" name="c" value="site" />
                <input type="hidden" name="a" value="entry" />
                <input type="hidden" name="m" value="lexiangpingou" />
                <input type="hidden" name="do" value="member" />
                <input type="hidden" name="op" value="upd" />
				 <input type="hidden" name="b" value="1" />
				 <input type="hidden" name="id" value="{$id}" />
	   	<div class="panel panel-default">
	   	<div class="panel-heading">
			店铺设置
		</div>
	   	<div class="panel-body table-responsive">
	   		 <div class="form-group">
                            <label class="col-xs-10 col-sm-3 col-md-3 control-label">店铺名称</label>
                            <div class="col-xs-12 col-sm-9 col-md-8 col-lg-8">
                                <input type="text" name="shopname" class="form-control"  value="{$member['shopname']}"/>
                            </div>
                        </div>
						
	   	</div>
	<!--	<div class="form-group">
                    <label class="col-xs-12 col-sm-2 col-md-2 col-lg-2 control-label">管理员</label>
                    <div class="col-sm-8 col-lg-9 col-xs-12">
                        <select name="tuan" class="form-control">
                            <option value="">不限</option>
                          {loop $mems $item}
						  <option value="{$item['id']}" >{$item['nickname']}</option>                  
						{/loop}
                        </select>
                    </div>
                </div>
		<div class="panel-body table-responsive">
	   		 <div class="form-group">
                            <label class="col-xs-10 col-sm-3 col-md-3 control-label">管理员{$_W['role']}</label>
                            <div class="col-xs-12 col-sm-9 col-md-8 col-lg-8">
							{if $_W['role']=='manage'}
                                <input type="text" name="shopname" class="form-control"  value="{$member['shopname']}"/>
								{else}
								{/if}
                            </div>
                        </div>
						
	   	</div>-->
	   	</div>
		<button type="submit" class="btn btn-primary span2" name="confirmsend" value="yes">确认提交</button>
                   
	</form>
</div>
 
{/if}
{if $op=='member_detail'}

<style type="text/css">
.main .form-horizontal .form-group{margin-bottom:0;}
.main .form-horizontal .modal .form-group{margin-bottom:15px;}
#modal-confirmsend .control-label{margin-top:0;}
</style>
<div class="main">
	<form class="form-horizontal form" action="" method="post" enctype="multipart/form-data" onsubmit="return formcheck(this)">
		<input type="hidden" name="dispatchid" value="{$dispatch['id']}" />
		
	   	<div class="panel panel-default">
	   	<div class="panel-heading">
			团队成员
		</div>
	   	<div class="panel-body table-responsive">
	   		<table class="table table-hover">
	   			<thead class="navbar-inner">
	   				<tr>
	   					
	   					<th style="width:70px;">昵称</th>
						<th style="width:70px;">加入时间</th>
	   					<th style="width:100px;">消费金额</th>
	   								   					
	   				</tr>
	   			</thead>
	   			<tbody>
	   				{loop $orders $item}
					
	   				<tr>
	   					<td>{$item['nickname']}</td>
						<td>{php echo date('Y-m-d H:i:s', $item['intertime'])}</td>
	   					<td>{$item['total']}</td>
	   					  					
	   				</tr>
	   				{/loop}
	   			</tbody>
	   		</table>
	   	</div>
	   	</div>
		
	</form>
</div>
{/if}

		<script>
		if (document.getElementsByClassName("cancelJ").length>0){
			var cancelJs = document.getElementsByClassName("cancelJ");
			for (var i = 0; i < cancelJs.length; i++){
				cancelJs[i].onclick = function(event) {
				event.preventDefault();
				if (confirm("取消兼职后该兼职人员将清除所有层级关系，确定取消吗？")){
					location.href = event.target.href;
				}
			}		

		}
		}
		if (document.getElementById("link-icon1")){
		var linkicon=document.getElementById("link-icon");
		var linkicon2=document.getElementById("link-icon1");
		
		linkicon2.onmouseleave = function () {
			linkicon.style.setProperty( 'display', 'none' );
		}
		
		linkicon2.onmouseover = function () {
			linkicon.style.setProperty( 'display', 'block' );
		}
		
		linkicon.onclick=function (ev) {
			document.getElementById('detailimg').src='{TG_URL_WRES}images/function/sqjz.jpg';
			document.getElementById("detailshow").style.setProperty("display","block");
		}
		}
            function displayUrl(lurl, surl) {
                require(['jquery', 'util'], function($, u) {
                    var content = '<p class="form-control-static" style="word-break:break-all">菜单使用链接(需要oAuth): <br>' + lurl + '</p>';
                    content += '<p class="form-control-static" style="word-break:break-all">自动回复使用链接: <br>' + surl + '</p>';
                    var footer =
                            '<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>' +
                            '<button type="button" class="btn btn-primary">复制菜单链接</button>' +
                            '<button type="button" class="btn btn-success">复制自动回复链接</button>';
                    var diaobj = u.dialog('查看URL', content, footer);
                    diaobj.find('.btn-default').click(function() {
                        diaobj.modal('hide');
                    });
                    diaobj.on('shown.bs.modal', function(){
                        u.clip(diaobj.find('.btn-primary')[0], lurl);
                        u.clip(diaobj.find('.btn-success')[0], surl);
                    });
                    diaobj.modal('show');
                });
            }
            function displayQr(url) {
                require(['jquery', 'util'], function($, u) {
                    var content = '<div class="panel panel-default text-center"><img src="' + url + '" alt="文章地址二维码" class="img-rounded"></div>';
                    var footer =
                            '<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>';
                    var diaobj = u.dialog('查看URL二维码', content, footer);
                    diaobj.find('.btn-default').click(function() {
                        diaobj.modal('hide');
                    });
                    diaobj.modal('show');
                });
            }
        </script>

{php include wl_template('common/footer');}
